<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="last">上一页</button>
    <button class="next">下一页</button>
    <div class="box"></div>
    
</body>
</html>
<script>
    function fn (type , src ,page, execute ) {
        var xtm = new XMLHttpRequest()

        xtm.open(type , src + '?' + 'page='+ page +'&count=10' )

        xtm.onreadystatechange = function (){
            if(xtm.readyState == 4 ){
                console.log(JSON.parse(xtm.responseText));
                execute(JSON.parse(xtm.responseText))
            }
        }

        xtm.send()
    }
    
    function render (page) {
        fn('get' , 'https://yantianfeng.com/api/emotion' ,page, function(data){
            let box = document.querySelector('.box')
            box.innerHTML = ''
            for(let i = 0 ; i < data.emotions.length ; i++){
                box.innerHTML += `<img src="${data.emotions[i].url}" alt=""> <h2>${data.emotions[i].title}</h2>`
            }
        } )
    }
    let last = document.querySelector('.last')
    let next = document.querySelector('.next')
    
    let page = 1
    last.onclick = ()=>{
        if(page > 1){
            page--
            render(page)
        }
    }
    next.onclick = ()=>{
        if(page < 4){
            page++
            render(page)
        }
    }
    fn('get' , 'https://yantianfeng.com/api/emotion' , 1 , function(data){
            let box = document.querySelector('.box')
            box.innerHTML = ''
            for(let i = 0 ; i < data.emotions.length ; i++){
                box.innerHTML += `<img src="${data.emotions[i].url}" alt=""> <h2>${data.emotions[i].title}</h2>`
            }
        })
</script>